﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace com.lover.common
{
    public class DebugLogHelper
    {
        private static DebugLogHelper _instance = new DebugLogHelper();
        public static DebugLogHelper getInstance() { return _instance; }

        private bool _enable = false;
        private string _filename = "command.log";
        public DebugLogHelper() { }
        public void log(string text)
        {
            if (!_enable) return;
            FileInfo finfo = new FileInfo(_filename);
            FileStream stream = null;
            if (!finfo.Exists) stream = finfo.Create();
            else stream = finfo.Open(FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
            StreamWriter wr = new StreamWriter(stream, Encoding.UTF8);
            DateTime dt = DateTime.Now;
            wr.WriteLine(String.Format("[{0:G}]:{1}", dt, text));
            wr.Close();
            stream.Close();
        }
    }
}
